  <template> 
	<div class="JNPF-common-layout">
		<div class="JNPF-common-layout-center">
			<el-row class="JNPF-common-search-box" :gutter="16">
				<el-form @submit.native.prevent>
					<el-col :span="6">
						<el-form-item label="事故名称">
							<el-input v-model="query.sgmc" placeholder="事故名称" clearable  />
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="事故部门">
							<el-select v-model="query.sgbm" placeholder="事故部门" clearable >
								<el-option v-for="(item, index) in sgbmOptions" :key="index" :label="item.F_FullName" :value="item.F_Id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<!-- <el-col :span="6">
						<el-form-item label="审核状态">
							<el-select v-model="query.shzt" placeholder="审核状态" clearable >
								<el-option v-for="(item, index) in shztOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col> -->
					<!-- <template v-if="showAll"> -->
						<el-col :span="6">
							<el-form-item label="发生时间">
								<el-date-picker v-model="query.fssj" placeholder="发生时间" clearable format="yyyy-MM-dd HH:mm:ss" type="datetime"  />
							</el-form-item>
						</el-col>
					<!-- </template> -->
					<el-col :span="6">
					<el-form-item>
						<el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
						<el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
						<el-button type="text" icon="el-icon-arrow-down" @click="showAll=true" v-if="!showAll">展开</el-button>
						<el-button type="text" icon="el-icon-arrow-up" @click="showAll=false" v-else>收起</el-button>
					</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<div class="JNPF-common-layout-main JNPF-flex-main">
				<div class="JNPF-common-head">
					<div>
						<el-button type="text" icon="el-icon-download" @click="exportData()">
							导出
						</el-button>
					</div>
					<div class="JNPF-common-head-right">
						<el-tooltip effect="dark" content="刷新" placement="top">
							<el-link icon="icon-ym icon-ym-Refresh JNPF-common-head-icon" :underline="false"  @click="reset()" />
						</el-tooltip>
						<screenfull :isContainer="true" />
						<el-tooltip effect="dark" content="列设置" placement="top">
							<el-link icon="icon-ym icon-ym-options JNPF-common-head-icon" :underline="false" />
						</el-tooltip>
					</div>
				</div>
				<JNPF-table v-loading="listLoading" :data="list">
					<el-table-column prop="sgmc" label="事故名称" align="left" />
					<el-table-column label="事故部门"  prop="sgbm" algin="left">
						<template slot-scope="scope">{{ scope.row.sgbm | dynamicText(sgbmOptions) }}</template>
					</el-table-column>
					<el-table-column prop="fsdd" label="发生地点" align="left" />
					<el-table-column prop="fssj" label="发生时间" align="left" />
					<el-table-column prop="sgyy" label="事故原因" align="left" />
					<el-table-column prop="sgms" label="事故描述" align="left" />
					<el-table-column label="上报人"  prop="sbr" algin="left">
						<template slot-scope="scope">{{ scope.row.sbr | dynamicText(sbrOptions) }}</template>
					</el-table-column>
					<el-table-column label="审核状态"  prop="shzt" algin="left">
						<template slot-scope="scope">{{ scope.row.shzt | dynamicText(shztOptions) }}</template>
					</el-table-column>
					<el-table-column label="审批人"  prop="spr" algin="left">
						<template slot-scope="scope">{{ scope.row.spr | dynamicText(sprOptions) }}</template>
					</el-table-column>
					<el-table-column label="操作" fixed="right" width="100">
						<template slot-scope="scope">
							<el-button type="text" @click="addOrUpdateHandle(scope.row.id,true)" >
								详情
							</el-button>
						</template>
					</el-table-column>
				</JNPF-table>
				<pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />
			</div>
		</div>
		<JNPF-Form v-if="formVisible" ref="JNPFForm" @refresh="refresh" />
		<ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" />
	</div>

</template> 
<script>
    import request from '@/utils/request'
    import {getDictionaryDataSelector} from '@/api/systemData/dictionary'
    import JNPFForm from './Form'
    import {previewDataInterface} from '@/api/systemData/dataInterface'

    export default {
        components: {JNPFForm},
        data() {
            return {
                showAll: false,
                query: {
					sgmc:undefined,
					sgbm:undefined,
					shzt:1,
					fssj:undefined,

                },
                defaultProps: {
                    children: 'children',
                    label: 'fullName'
                },
                list: [],
                listLoading: true,
                total: 0,
                listQuery: {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                },
                formVisible: false,
                exportBoxVisible: false,
                columnList: [
					{prop: 'sgmc', label: '事故名称'},
					{prop: 'sgbm', label: '事故部门'},
					{prop: 'fsdd', label: '发生地点'},
					{prop: 'fssj', label: '发生时间'},
					{prop: 'sgyy', label: '事故原因'},
					{prop: 'sgms', label: '事故描述'},
					{prop: 'sbr', label: '上报人'},
					{prop: 'shzt', label: '审核状态'},
					{prop: 'spr', label: '审批人'},

                ],
				sgbmOptions:[],
				shlbOptions:[{"fullName":"人员伤亡事故","id":"0"},{"fullName":"火灾爆炸事故","id":"1"},{"fullName":"危化品泄漏事故","id":"2"},{"fullName":"设备事故","id":"3"},{"fullName":"工艺事故","id":"4"}],
				sbrOptions:[],
				sgdjOptions:[{"fullName":"特别重大","id":"0"},{"fullName":"重大","id":"1"},{"fullName":"较大","id":"2"},{"fullName":"一般","id":"3"}],
				zgzrrOptions:[],
				shztOptions:[{"fullName":"待审核","id":"-1"},{"fullName":"已通过","id":"1"},{"fullName":"未通过","id":"0"}],
				sprOptions:[],

            }
        },
        computed: {},
        created() {
			this.initData();

			this.getsgbmOptions();
			this.getsbrOptions();
			this.getzgzrrOptions();
			this.getsprOptions();

        },
        methods: {
			getsgbmOptions()
			{
				previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
					this.sgbmOptions = res.data
				})
			},
			getsbrOptions()
			{
				previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
					this.sbrOptions = res.data
				})
			},
			getzgzrrOptions()
			{
				previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
					this.zgzrrOptions = res.data
				})
			},
			getsprOptions()
			{
				previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
					this.sprOptions = res.data
				})
			},


            initData() {
                this.listLoading = true;
                let query = {
                    ...this.listQuery,
                    ...this.query
                };
                request({
                    url: `/api/System/qyaqscSgbgxx`,
                    method: 'get',
                    data: query
                }).then(res => {
                    this.list = res.data.list
                    this.total = res.data.pagination.total
                    this.listLoading = false
                    this.$nextTick(() => {
                        this.tableHeight = "100%"
                    });
                })
            },
            addOrUpdateHandle(id,isDetail) {
                this.formVisible = true
                this.$nextTick(() => {
                    this.$refs.JNPFForm.init(id,isDetail)
                })
            },
            exportData() {
                this.exportBoxVisible = true
                this.$nextTick(() => {
                    this.$refs.ExportBox.init(this.columnList)
                })
            },
            download(data) {
                let query = {...data, ...this.listQuery, ...this.query}
                request({
                    url: `/api/System/qyaqscSgbgxx/Actions/Export`,
                    method: 'POST',
                    data: query
                }).then(res => {
                    if (!res.data.url) return
                    window.location.href = this.define.comUrl + res.data.url
                    this.$refs.ExportBox.visible = false
                    this.exportBoxVisible = false
                })
            },
            search() {
                this.listQuery = {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            },
            refresh(isrRefresh) {
                this.formVisible = false
                if (isrRefresh) this.reset()
            },
            reset() {
                for (let key in this.query) {
                    this.query[key] = undefined
                }
                this.listQuery = {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            }
        }
    }
</script>